package streams;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class FileToWordsBuilder {
	Stream.Builder<String> builder = Stream.builder();

	public FileToWordsBuilder(String filePath) throws Exception {
		Files.lines(Paths.get(filePath)).skip(1).forEach(line -> {
			for (String w : line.split("[ .?,]+")) {
				builder.add(w);
			}
		});
	}

	Stream<String> stream() {
		return builder.build();
	}

	public static void main(String[] args) throws Exception {
		new FileToWordsBuilder("src\\main\\java\\streams\\Cheese.dat").stream().limit(7).map(w -> w + " ")
				.forEach(System.out::print);
	}
}
